package org.mashibing.service.impl;

import org.mashibing.dto.PassengerUser;
import org.mashibing.dto.ResponseResult;
import org.mashibing.dto.TokenResult;
import org.mashibing.remote.ServicePassengerUserClient;
import org.mashibing.service.UserService;
import org.mashibing.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author:
 * @create: 2024/4/1 17:00
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    @Override
    public ResponseResult<PassengerUser> getUserByPhone(String accessToken) {
        // 根据accessToken获取手机号
        TokenResult tokenResult = JwtUtils.pareToken(accessToken);
        String passengerPhone = tokenResult.getPhone();

        // 根据手机号查询用户信息
        return servicePassengerUserClient.getUser(passengerPhone);
    }
}
